/// @tags: Binom Catalan
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

namespace BlueQuantum {

typedef unsigned int uint;
typedef long long LL;

int const N = 1e5 + 5;

int cnt;
LL p, n, l, r;
LL pri[N], inv[N], fac[N], c[N][40];

inline LL qpow(LL base, LL exp) {
  LL res = 1;
  for (; exp; base = base * base % p, exp >>= 1)
    if (exp & 1) res = (res * base) % p;
  return res;
}

inline void prework() {
  fac[0] = inv[0] = fac[1] = inv[1] = 1;
  LL x = p, phi = p;
  for (int i = 2; (LL)i * i <= x; ++i) {
    if (x % i) continue;
    pri[++cnt] = i;
    phi = phi / i * (i - 1);
    while (x % i == 0) x /= i;
  }
  if (x != 1) pri[++cnt] = x, phi = phi / x * (x - 1);
  for (int i = 2; i <= n; ++i) {
    LL x = i;
    for (int j = 1; j <= cnt; ++j) {
      c[i][j] = c[i - 1][j];
      while (x % pri[j] == 0) x /= pri[j], c[i][j]++;
    }
    fac[i] = fac[i - 1] * x % p;
    inv[i] = qpow(fac[i], phi - 1);
  }
}

inline LL C(LL n, LL m) {
  if (m < 0 || n < m) return 0;
  if (m == 0) return 1;
  LL tmp = fac[n] * inv[m] % p * inv[n - m] % p;
  for (int i = 1; i <= cnt; ++i)
    tmp = tmp * qpow(pri[i], c[n][i] - c[m][i] - c[n - m][i]) % p;
  return tmp;
}

inline int main() {
  cin >> n >> p >> l >> r;
  prework();
  uint ans = 0;
  r = min(n, r);
  for (int i = 0; i <= n - l; ++i) {
    LL tmp = C(n - i, (n - i - l) >> 1) - C(n - i, (n - i - r - 1) >> 1);
    if (tmp < 0) tmp += p;
    if ((ans += tmp * C(n, i) % p) >= p) ans -= p;
  }
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("zero.in", "r", stdin);
  freopen("zero.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
